﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CE.Mail;
using CE.Image;
using CE.Global;
using CE.Database;
using CE.User;
using CE.PostCode;
using CE.PersonalAccident;
using CE.Security;
using CE.Provider;
using CE.StreetDirectory;
using CE.Payment;

public partial class personal_accident_proposalforms_eq_proposal_form : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (Session[CE.Global.General.UserId] != null && Session[CE.Global.General.UserTypeId] != null)
        //{
        //    if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) !=
        //        Convert.ToInt32(CE.Global.CEUserType.Customer) && Convert.ToInt32(Session[CE.Global.General.UserTypeId]) !=
        //        Convert.ToInt32(CE.Global.CEUserType.Provider))
        //    {
        //        Response.Redirect("~/User/LoginAndRegister.aspx");
        //    }
        //}
        //else
        //{
        //    Response.Redirect("~/User/LoginAndRegister.aspx");
        //}
        //if (Session[CE.Global.General.Guest].ToString() == "Provider")
        //{
        //    Response.Redirect("~/Provider/ProviderSecureLogin.aspx");
        //}
        if (Session[CE.Global.General.PAResultId] != null)
        {
            if (Session[General.ProviderCompanyId] == null)
            {
                Response.Redirect("~/personal-accident/results.aspx");
            }

            if (Session[General.ProviderCompanyId].ToString() != "35")
            {
                Response.Redirect("~/personal-accident/results.aspx");
            }
        }
        else
        {
            Response.Redirect("~/personal-accident/results.aspx");
        }

        if (!IsPostBack)
        {
            if (Session[General.PAResultId] != null)
            {
                LoadPremium();
                LoadCoverInfo();
                EnableChildPanels();
            }
            else
            {
                Response.Redirect("~/personal-accident/personal-accident.aspx");
            }

            #region Date

            ddlChildDOB1.StartYear = CE.Global.General.GetUTCDateTime().Year - 18;
            ddlChildDOB1.EndYear = CE.Global.General.GetUTCDateTime().Year;

            ddlChildDOB2.StartYear = CE.Global.General.GetUTCDateTime().Year - 18;
            ddlChildDOB2.EndYear = CE.Global.General.GetUTCDateTime().Year;

            ddlChildDOB3.StartYear = CE.Global.General.GetUTCDateTime().Year - 18;
            ddlChildDOB3.EndYear = CE.Global.General.GetUTCDateTime().Year;

            ddlChildDOB4.StartYear = CE.Global.General.GetUTCDateTime().Year - 18;
            ddlChildDOB4.EndYear = CE.Global.General.GetUTCDateTime().Year;

            ddlChildDOB5.StartYear = CE.Global.General.GetUTCDateTime().Year - 18;
            ddlChildDOB5.EndYear = CE.Global.General.GetUTCDateTime().Year;

            #endregion

            #region Load Combo

            InsurerDB _insurerdb = new InsurerDB();
            DataTable dtPreInsurerComp = _insurerdb.GetPreInsurer(500, 1);
            ddlInsuranceCompany.DataSource = dtPreInsurerComp;
            ddlInsuranceCompany.DataTextField = dtPreInsurerComp.Columns[0].ColumnName.ToString();
            ddlInsuranceCompany.DataValueField = dtPreInsurerComp.Columns[1].ColumnName.ToString();
            ddlInsuranceCompany.DataBind();
            ddlInsuranceCompany.Items.Insert(0, new ListItem("Select", "-1"));

            int _year;
            int startyear = CE.Global.General.GetUTCDateTime().Year;
            int endyear = CE.Global.General.GetUTCDateTime().Year + 10;
            for (_year = endyear; _year >= startyear; _year--)
            {
                ddlCardExpiryYear.Items.Insert(0, new ListItem(_year.ToString("0000"), _year.ToString("00")));
            }
            ddlCardExpiryYear.Items.Insert(0, new ListItem("yyyy", "-1"));


            #endregion

            #region Validation Effect

            txtName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtName.ClientID + "','" + rfvName.ClientID + "','" + revName.ClientID + "')");
            txtPostCode.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtPostCode.ClientID + "','" + rfvPostCode.ClientID + "','" + revPostCode.ClientID + "')");
            txtUnit1.Attributes.Add("onblur", "ShowValidationEffect('" + txtUnit1.ClientID + "','" + rfvUnit1.ClientID + "')");
            txtUnit2.Attributes.Add("onblur", "ShowValidationEffect('" + txtUnit2.ClientID + "','" + rfvUnit2.ClientID + "')");
            txtAddress.Attributes.Add("onblur", "ShowValidationEffect('" + txtAddress.ClientID + "','" + rfvAddress.ClientID + "')");
            //txtAddress.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtAddress.ClientID + "','" + rfvAddress.ClientID + "','" + revAddress.ClientID + "')");
            txtEmail.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtEmail.ClientID + "','" + rfvEmail.ClientID + "','" + revEmail.ClientID + "')");
            //ddlNatureOfBusiness.Attributes.Add("onblur", "ShowValidationEffect('" + ddlNatureOfBusiness.ClientID + "','" + rfvNatureofBusiness.ClientID + "')");

            txtSpouseName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtSpouseName.ClientID + "','" + rfvSpouseName.ClientID + "','" + revSpouseName.ClientID + "')");
            txtChildName1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName1.ClientID + "','" + rfvChildName1.ClientID + "','" + revChildName1.ClientID + "')");
            txtChildName2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName2.ClientID + "','" + rfvChildName2.ClientID + "','" + revChildName2.ClientID + "')");
            txtChildName3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName3.ClientID + "','" + rfvChildName3.ClientID + "','" + revChildName3.ClientID + "')");
            txtChildName4.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName4.ClientID + "','" + rfvChildName4.ClientID + "','" + revChildName4.ClientID + "')");
            txtChildName5.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName5.ClientID + "','" + rfvChildName5.ClientID + "','" + revChildName5.ClientID + "')");

            txtNameoftheCard.Attributes.Add("onblur", "ShowValidationEffect('" + txtNameoftheCard.ClientID + "','" + rfvNameoftheCard.ClientID + "')");
            txtIssuingBank.Attributes.Add("onblur", "ShowValidationEffect('" + txtIssuingBank.ClientID + "','" + rfvIssuingBank.ClientID + "')");
            txtCardNo1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo1.ClientID + "','" + rfvCardNo1.ClientID + "','" + revCardNo1.ClientID + "')");
            txtCardNo2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo2.ClientID + "','" + rfvCardNo2.ClientID + "','" + revCardNo2.ClientID + "')");
            txtCardNo3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo3.ClientID + "','" + rfvCardNo3.ClientID + "','" + revCardNo3.ClientID + "')");
            txtCardNo4.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo4.ClientID + "','" + rfvCardNo4.ClientID + "','" + revCardNo4.ClientID + "')");
            ddlCardExpiryMonth.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCardExpiryMonth.ClientID + "','" + rfvCardExpiryMonth.ClientID + "')");
            ddlCardExpiryYear.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCardExpiryYear.ClientID + "','" + rfvCardExpiryYear.ClientID + "')");

            rdoYesPerformManual.Attributes.Add("onblur", "CheckPerformManualValidationCss();");
            rdoNoPerformManual.Attributes.Add("onblur", "CheckPerformManualValidationCss();");
            rdoYesHazadousHobby.Attributes.Add("onblur", "CheckHazadousHobbyValidationCss();");
            rdoNoHazadousHobby.Attributes.Add("onblur", "CheckHazadousHobbyValidationCss();");
            rdoYesPhysicaldefect.Attributes.Add("onblur", "CheckPhysicaldefectValidationCss();");
            rdoNoPhysicaldefect.Attributes.Add("onblur", "CheckPhysicaldefectValidationCss();");
            rdoYesOtherInsurence.Attributes.Add("onblur", "CheckOtherInsurenceValidationCss();");
            rdoNoOtherInsurence.Attributes.Add("onblur", "CheckOtherInsurenceValidationCss();");
            rdoYesDeclined.Attributes.Add("onblur", "CheckAnyClaimsValidationCss();");
            rdoNoDeclined.Attributes.Add("onblur", "CheckAnyClaimsValidationCss();");
            rdoYesInsuranceCancelled.Attributes.Add("onblur", "CheckInsuranceCancelledValidationCss();");
            rdoNoInsuranceCancelled.Attributes.Add("onblur", "CheckInsuranceCancelledValidationCss();");
            rdoVisa.Attributes.Add("onblur", "CheckCardTypeValidationCss();");
            rdoMasterCard.Attributes.Add("onblur", "CheckCardTypeValidationCss();");

            #endregion

            Session[General.ViewedDetailsId] = LogUserViewedHistory().ToString();

            if (Session[General.UserId] != null)
            {
                ShowUserDetails();
            }
            else if (Session[General.PAPersonnelId] != null
                && Session[General.PAEmail] != null
                && Session[General.PAPhoneNo] != null
                && Session[General.PAUserName] != null)
            {
                txtName.Text = Session[General.PAUserName].ToString();
                txtMobileNo.PhoneNo = Session[General.PAPhoneNo].ToString();
                txtEmail.Text = Session[General.PAEmail].ToString();
            }
        }

        if (rdoAdministrative.Checked || rdoSupervisory.Checked || rdoManual.Checked) txtOccDuties.Text = "1";
        if (rdoYesPerformManual.Checked || rdoNoPerformManual.Checked) txtPerformManual.Text = "1";
        if (rdoYesHazadousHobby.Checked || rdoNoHazadousHobby.Checked) txtHazadousHobby.Text = "1";
        if (rdoYesPhysicaldefect.Checked || rdoNoPhysicaldefect.Checked) txtPhysicaldefect.Text = "1";
        if (rdoYesOtherInsurence.Checked || rdoNoOtherInsurence.Checked) txtOI.Text = "1";
        if (rdoYesDeclined.Checked || rdoNoDeclined.Checked) txtDeclinedIns.Text = "1";
        if (rdoYesInsuranceCancelled.Checked || rdoNoInsuranceCancelled.Checked) txtInsuranceCancelled.Text = "1";
        if (rdoVisa.Checked || rdoMasterCard.Checked) txtCardType.Text = "1";
    }

    protected void ibtnBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/personal-accident/results.aspx");
    }

    protected void ibtPostCode_Click(object sender, ImageClickEventArgs e)
    {
        GetPostCode();
    }

    protected void ibtSubmit_Click(object sender, ImageClickEventArgs e)
    {
        if (Session[CE.Global.General.PAResultId] != null)
        {
            if (Session[General.ProviderCompanyId].ToString() != "35")
            {
                Response.Redirect("~/personal-accident/results.aspx");
            }
        }
        else
        {
            Response.Redirect("~/personal-accident/results.aspx");
        }
        CheckValidation();
        ChangeValidationEffectServerSide("proposal");
        if (IsValid)
        {
            Int64 _proposalresult = 0;
            Int64 _childresult = 0;

             EQProposal _eqproposal = new EQProposal();
             EQProposalDB _eqproposaldb = new EQProposalDB();

            if (Session[General.PAProposalId] != null)
            {
                _eqproposal.PAProposalId = Convert.ToInt64(Session[General.PAProposalId].ToString());
            }
            else
            {
                _eqproposal.PAProposalId = 0;
            }
            _eqproposal.PAId = Convert.ToInt64(Session[General.PAId].ToString());
            _eqproposal.PACompanyId = Convert.ToInt64(lblCompanyId.Text.ToString());
            _eqproposal.PAInsId = Convert.ToInt64(Session[General.PAResultId].ToString());
            _eqproposal.Name = txtName.Text.ToUpper();
            _eqproposal.PostalCode = txtPostCode.Text.Trim();
            _eqproposal.UnitNo = txtUnit1.Text.Trim();
            _eqproposal.HomeNo = txtUnit2.Text.Trim();
            _eqproposal.Address = txtAddress.Text.Trim();
            _eqproposal.Gender = ddlGender.GetGender();
            _eqproposal.NRICNo = ddlIdNumber.GetIdNumber();
            _eqproposal.Nationality = ddlNationality.GetNationality();
            _eqproposal.MobileNo = txtMobileNo.GetPhoneNo();
            _eqproposal.HomePhoneNo = txtHomePhoneNo.GetPhoneNo();
            _eqproposal.OfficePhoneNo = txtOfficePhoneNo.GetPhoneNo();
            _eqproposal.Email = txtEmail.Text.Trim();
            _eqproposal.SpouseName = txtSpouseName.Text.ToUpper();
            _eqproposal.SpouseGender = SpouseGender(ddlGender.GetGender()); //ddlSpouseGender.GetGender();
            _eqproposal.SpouseNRICNo = ddlSpouseIdNumber.GetIdNumber();

            string occduty = "";

            if (rdoAdministrative.Checked)
                occduty = "Administrative";
            else if (rdoSupervisory.Checked)
                occduty = "Supervisory";
            else
                occduty = "Manual";

            _eqproposal.OccupationDuty = occduty;

            _eqproposal.HasMachinery = rdoYesPerformManual.Checked;
            _eqproposal.Machinery = txtPerformManualReason.Text.Trim();
            _eqproposal.HasEngagedSportsActivities = rdoYesHazadousHobby.Checked;
            _eqproposal.EngagedSportsActivities = txtHazadousHobbyReason.Text.Trim();
            _eqproposal.HasPhysicalDefects = rdoYesPhysicaldefect.Checked;
            _eqproposal.PhysicalDefects = txtPhysicaldefectReason.Text.Trim();
            _eqproposal.HasOtherInsurance = rdoYesOtherInsurence.Checked;
            _eqproposal.OtherInsuranceCompany = ddlInsuranceCompany.Text;
            _eqproposal.OtherInsuranceDetails = txtInsDetails.Text.Trim();
            //_eqproposal.HasAnyClaimsfromInsurer = rdoYesAnyClaims.Checked;
            //_eqproposal.AnyClaimsfromInsurer = txtAnyClaimsReason.Text.Trim();
            _eqproposal.HasDeclinedInsurance = rdoYesDeclined.Checked;
            _eqproposal.DeclinedInsurance = txtDeclinedIns.Text;
            _eqproposal.HasIncreasePremium = rdoYesInsuranceCancelled.Checked;
            _eqproposal.IncreasePremium = txtInsuranceCancelledReason.Text.Trim();
            _eqproposal.ChequeNo = "";
            _eqproposal.BankName = "";
            _eqproposal.PamentType = "CreditCard";

            if (Session[CE.Global.General.UserId] != null)
            {
                _eqproposal.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
            }
            else if (Session[CE.Global.General.PAPersonnelId] != null)
            {
                _eqproposal.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.PAPersonnelId].ToString());
            }
            _eqproposal.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
            _eqproposal.Status = true;

            _proposalresult = _eqproposaldb.Insert(_eqproposal);
            Session[General.PAProposalId] = _proposalresult;
            if (_proposalresult > 0)
            {
                Int64 _paymentresult = 0;
                Payment _payment = new Payment();
                PaymentDB _paymentdb = new PaymentDB();

                _payment.CXPaymentId = 0;
                _payment.RefId = Convert.ToInt64(Session[General.PAId].ToString());
                _payment.ProviderCompanyId = Convert.ToInt64(lblCompanyId.Text.ToString());
                _payment.InsuranceType = "PA";
                _payment.NameoftheCard = txtNameoftheCard.Text.ToUpper();
                _payment.IssuingBankName = txtIssuingBank.Text.Trim();
                _payment.CreditCardNo = txtCardNo1.Text.Trim() + "" + txtCardNo2.Text.Trim() + "" + txtCardNo3.Text.Trim() + "" + txtCardNo4.Text.Trim();
                _payment.CardExpiryMonth = ddlCardExpiryMonth.Text;
                _payment.CardExpiryYear = ddlCardExpiryYear.Text;
                if (rdoVisa.Checked == true)
                {
                    _payment.CardType = "Visa";
                }
                else
                {
                    _payment.CardType = "MasterCard";
                }
                _payment.Status = true;
                if (Session[CE.Global.General.UserId] != null)
                {
                    _payment.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                }
                else if (Session[General.PAPersonnelId] != null)
                {
                    _payment.RefCEUserId = Convert.ToInt64(Session[General.PAPersonnelId].ToString());
                }
                _paymentresult = _paymentdb.Insert(_payment);

                if (_paymentresult > 0)
                {
                    if (txtCHCount.Text.Trim() != "0")
                    {
                        if (!SaveChildInfo(_proposalresult))
                        {
                            lblMessage.Text = "Child details failed to save!";
                        }
                        else
                        {
                            _childresult = 1;
                        }
                    }
                    else
                    {
                        _childresult = 1;
                    }
                    if (_childresult > 0)
                    {
                        ProposalNotification();
                        UserConfirmation _userconfirm = new UserConfirmation();
                        UserConfirmationDB _userconfirmdb = new UserConfirmationDB();
                        _userconfirm.ConfirmationType = "PA";
                        _userconfirm.CurrentStep = 3;

                        _userconfirm.UserSelectedId = Convert.ToInt64(Session[General.PAResultId].ToString());
                        _userconfirm.FirstStepId = Convert.ToInt64(Session[General.PAId].ToString());
                        if (Session[General.UserId] != null)
                        {
                            _userconfirm.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                        }
                        else if (Session[CE.Global.General.PAPersonnelId] != null)
                        {
                            _userconfirm.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.PAPersonnelId].ToString());
                        }
                        _userconfirm.Status = true;
                        _userconfirm.IsConfirm = true;
                        _userconfirm.ResultStatus = "Complete";
                        _userconfirm.IsComplete = true;
                        Int64 _result = _userconfirmdb.Insert(_userconfirm);

                        if (_result > 0)
                        {
                            string _provideid = Encode("35");
                            General.ClearAllSession(this.Page, "ALL");
                            Response.Redirect("~/personal-accident/usermessage.aspx?pcid=" + _provideid);
                        }
                        else
                        {
                            lblMessage.Text = "Can't update confirmation status.";
                        }
                    }
                }
                else
                {
                    lblMessage.Text = "Payment Details Saved Faild.";
                }
            }
        }
    }

    protected void txtPostCode_TextChanged(object sender, EventArgs e)
    {
        GetPostCode();
    }

    protected void ddlAddressList_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAddressList.Items.Count > 0 && ddlAddressList.SelectedIndex >= 0)
        {
            txtAddress.Text = ddlAddressList.Text;
        }
    }

    public string Encode(string sData)
    {
        byte[] encData_byte = new byte[sData.Length];
        encData_byte = System.Text.Encoding.UTF8.GetBytes(sData);
        string encodedData = Convert.ToBase64String(encData_byte);
        return encodedData;
    }

    private void LoadPremium()
    {
        MyDatabase _db = new MyDatabase();
        string strSql = "";
        strSql = @"SELECT CompanyName,PlanName,TotalAnnualPremium,CAST(AnnualPremiumwithGST AS NUMERIC(10,2)) AS AnnualPremiumwithGST,BenefitName,PolicyType,PACompanyId FROM tblProviderPACompareBenefits, ";
        strSql = strSql + " tblProviderCompany WHERE ProviderCompanyId = PACompanyId AND PAInsId = " + Session[CE.Global.General.PAResultId].ToString();
        DataTable _dtResult = new DataTable();
        _dtResult = _db.GetDataTable(strSql);
        if (_dtResult.Rows.Count > 0)
        {
            lblProvider.Text = _dtResult.Rows[0]["CompanyName"].ToString();
            lblPlanName.Text = _dtResult.Rows[0]["PlanName"].ToString();
            //lblAnnualPremium.Text = _dtResult.Rows[0]["AnnualPremiumwithGST"].ToString();
            lblCompanyId.Text = _dtResult.Rows[0]["PACompanyId"].ToString();
            string _policy = _dtResult.Rows[0]["PolicyType"].ToString();
            if (_policy == "IND")
            {
                lblPolicyType.Text = "Individual";
                txtPolicyType.Text = "Individual";
            }
            else if (_policy == "INDSP")
            {
                lblPolicyType.Text = "Individual & Spouse";
                txtPolicyType.Text = "Individual & Spouse";
            }
            else if (_policy == "INDCHD")
            {
                lblPolicyType.Text = "Individual & Children";
                txtPolicyType.Text = "Individual & Children";
            }
            else if (_policy == "INDSPCHD")
            {
                lblPolicyType.Text = "Individual, Spouse & Children";
                txtPolicyType.Text = "Individual, Spouse & Children";
            }

            MyDatabase _db1 = new MyDatabase();
            string strSql1 = "";
            strSql1 = @"SELECT CAST(AnnualPremium AS NUMERIC(10,2)) AS AnnualPremiumwithGST FROM tblPAInsuranceSelectItem WHERE PAId = " + Session[CE.Global.General.PAId].ToString(); ;
            DataTable _dtResult1 = new DataTable();
            _dtResult1 = _db1.GetDataTable(strSql1);
            if (_dtResult1.Rows.Count > 0)
            {
                lblAnnualPremium.Text = _dtResult1.Rows[0]["AnnualPremiumwithGST"].ToString();
            }
        }
        else
        {
            lblProvider.Text = "";
            lblPlanName.Text = "";
            lblAnnualPremium.Text = "";
            lblCompanyId.Text = "0";
            lblPolicyType.Text = "";
            txtPolicyType.Text = "";
        }
    }

    private void LoadCoverInfo()
    {
        MyDatabase _db = new MyDatabase();
        string strSql = "";
        strSql = @"SELECT CoverType, NoOfChild FROM tblPAInsurance WHERE PAID =  " + Session[CE.Global.General.PAId].ToString(); ;
        DataTable _dtResult = new DataTable();
        _dtResult = _db.GetDataTable(strSql);
        if (_dtResult.Rows.Count > 0)
        {
            txtIsCover.Text = _dtResult.Rows[0]["CoverType"].ToString();
            if (_dtResult.Rows[0]["CoverType"].ToString() == "INDCHD" || _dtResult.Rows[0]["CoverType"].ToString() == "INDSPCHD")
            {
                txtCHCount.Text = _dtResult.Rows[0]["NoOfChild"].ToString();
            }
            else
            {
                txtCHCount.Text = "0";
            }
        }
        else
        {
            txtIsCover.Text = "IND";
            txtCHCount.Text = "0";
        }
    }

    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        return _userviewdb.LogViewedHistory("PA", Request, "Personal Accident ChinaTaiping proposal form.");
    }

    private bool SaveChildInfo(Int64 PAProposalId)
    {
        bool _result = false;
        ChildInfo _childinfo = new ChildInfo();
        ChildInfoDB _childinfodb = new ChildInfoDB();

        if (txtCHCount.Text.Trim() != "0")
        {
            int _childcount = Convert.ToInt32(txtCHCount.Text.Trim());
            int _insertcount = 0;

            for (int i = 1; i <= _childcount; i++)
            {
                _childinfo.PAChildId = 0;
                _childinfo.PAProposalId = PAProposalId;
                _childinfo.PAId = Convert.ToInt64(Session[CE.Global.General.PAId].ToString());
                _childinfo.PACompanyId = 35;
                if (Session[CE.Global.General.UserId] != null)
                {
                    _childinfo.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                }
                else
                {
                    _childinfo.RefCEUserId = 0;
                }
                _childinfo.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                _childinfo.Status = true;
                if (i == 1)
                {
                    _childinfo.Name = Server.HtmlEncode(General.ClearScriptTag(txtChildName1.Text.ToUpper()));
                    _childinfo.DOB = ddlChildDOB1.GetDate();
                    _childinfo.Gender = Convert.ToChar(ddlChildGender1.GetGender());
                    _childinfo.NRICNo = ddlChildIdNumber1.GetIdNumber();
                    //_childinfo.Nationality = ddlChildNationality1.GetNationality();
                    _childinfo.Relation = ChildRealtion(_childinfo.Gender);
                }
                else if (i == 2)
                {
                    _childinfo.Name = Server.HtmlEncode(General.ClearScriptTag(txtChildName2.Text.ToUpper()));
                    _childinfo.DOB = ddlChildDOB2.GetDate();
                    _childinfo.Gender = Convert.ToChar(ddlChildGender2.GetGender());
                    _childinfo.NRICNo = ddlChildIdNumber2.GetIdNumber();
                    //_childinfo.Nationality = ddlChildNationality2.GetNationality();
                    _childinfo.Relation = ChildRealtion(_childinfo.Gender);
                }
                else if (i == 3)
                {
                    _childinfo.Name = Server.HtmlEncode(General.ClearScriptTag(txtChildName3.Text.ToUpper()));
                    _childinfo.DOB = ddlChildDOB3.GetDate();
                    _childinfo.Gender = Convert.ToChar(ddlChildGender3.GetGender());
                    _childinfo.NRICNo = ddlChildIdNumber3.GetIdNumber();
                    //_childinfo.Nationality = ddlChildNationality3.GetNationality();
                    _childinfo.Relation = ChildRealtion(_childinfo.Gender);
                }
                else if (i == 4)
                {
                    _childinfo.Name = Server.HtmlEncode(General.ClearScriptTag(txtChildName4.Text.ToUpper()));
                    _childinfo.DOB = ddlChildDOB4.GetDate();
                    _childinfo.Gender = Convert.ToChar(ddlChildGender4.GetGender());
                    _childinfo.NRICNo = ddlChildIdNumber4.GetIdNumber();
                    //_childinfo.Nationality = ddlChildNationality4.GetNationality();
                    _childinfo.Relation = ChildRealtion(_childinfo.Gender);
                }
                else if (i == 5)
                {
                    _childinfo.Name = Server.HtmlEncode(General.ClearScriptTag(txtChildName5.Text.ToUpper()));
                    _childinfo.DOB = ddlChildDOB5.GetDate();
                    _childinfo.Gender = Convert.ToChar(ddlChildGender5.GetGender());
                    _childinfo.NRICNo = ddlChildIdNumber5.GetIdNumber();
                    //_childinfo.Nationality = ddlChildNationality5.GetNationality();
                    _childinfo.Relation = ChildRealtion(_childinfo.Gender);
                }

                if (_childinfodb.Insert(_childinfo) > 0)
                {
                    _insertcount++;
                    _result = true;
                }
            }
            _childinfodb = null;
            _childinfo = null;
        }
        return _result;
    }

    public string SpouseGender(string Gender)
    {
        string SGender = "M";
        if (Gender == "M")
        {
            SGender = "F";
        }
        else if (Gender == "F")
        {
            SGender = "M";
        }
        return SGender;
    }

    public string ChildRealtion(char Gender)
    {
        string Relation = "";
        if (Gender == 'M')
        {
            Relation = "Son";
        }
        else if (Gender == 'F')
        {
            Relation = "Daughter";
        }
        return Relation;
    }

    private void CheckValidation()
    {
        txtName.Text = General.ClearScriptTag(txtName.Text);
        txtPostCode.Text = General.ClearScriptTag(txtPostCode.Text);
        txtUnit1.Text = General.ClearScriptTag(txtUnit1.Text);
        txtUnit2.Text = General.ClearScriptTag(txtUnit2.Text);
        txtAddress.Text = General.ClearScriptTag(txtAddress.Text);
        //txtCompanyROCNo.Text = General.ClearScriptTag(txtCompanyROCNo.Text);
        txtSpouseName.Text = General.ClearScriptTag(txtSpouseName.Text);
        txtChildName1.Text = General.ClearScriptTag(txtChildName1.Text);
        txtChildName2.Text = General.ClearScriptTag(txtChildName2.Text);
        txtChildName3.Text = General.ClearScriptTag(txtChildName3.Text);
        txtChildName4.Text = General.ClearScriptTag(txtChildName4.Text);
        txtChildName5.Text = General.ClearScriptTag(txtChildName5.Text);
        txtPerformManualReason.Text = General.ClearScriptTag(txtPerformManualReason.Text);
        txtHazadousHobbyReason.Text = General.ClearScriptTag(txtHazadousHobbyReason.Text);
        txtPhysicaldefectReason.Text = General.ClearScriptTag(txtPhysicaldefectReason.Text);
        txtInsDetails.Text = General.ClearScriptTag(txtInsDetails.Text);
        txtDeclinedInsReason.Text = General.ClearScriptTag(txtDeclinedInsReason.Text);
        txtInsuranceCancelledReason.Text = General.ClearScriptTag(txtInsuranceCancelledReason.Text);
        txtNameoftheCard.Text = General.ClearScriptTag(txtNameoftheCard.Text);
        txtIssuingBank.Text = General.ClearScriptTag(txtIssuingBank.Text);
        txtOccDuties.Text = General.ClearScriptTag(txtOccDuties.Text);

        if (rdoAdministrative.Checked || rdoSupervisory.Checked || rdoManual.Checked)
        {
            rfvOccDuties.Enabled = false;
        }
        else
        {
            rfvPerformManualReason.Enabled = true;
        }

        #region Perform Manual
        if (rdoYesPerformManual.Checked)
        {
            rfvPerformManualReason.Enabled = true;
        }
        else
        {
            rfvPerformManualReason.Enabled = false;
        }
        #endregion

        #region Hazadous Hobby
        if (rdoYesHazadousHobby.Checked)
        {
            rfvHazadousHobbyReason.Enabled = true;

        }
        else
        {
            rfvHazadousHobbyReason.Enabled = false;
        }
        #endregion

        #region Physical defect
        if (rdoYesPhysicaldefect.Checked)
        {
            rfvPhysicaldefectReason.Enabled = true;
        }
        else
        {
            rfvPhysicaldefectReason.Enabled = false;
        }
        #endregion

        #region Other Insurence
        if (rdoYesOtherInsurence.Checked)
        {
            rfvInsuranceCompany.Enabled = true;
        }
        else
        {
            rfvInsuranceCompany.Enabled = false;
        }
        #endregion

        #region AnyClaims
        if (rdoYesDeclined.Checked)
        {
            rfvDeclinedInsReason.Enabled = true;
        }
        else
        {
            rfvDeclinedInsReason.Enabled = false;
        }
        #endregion

        #region Insurance Cancelled
        if (rdoYesInsuranceCancelled.Checked)
        {
            rfvInsuranceCancelledReason.Enabled = true;
        }
        else
        {
            rfvInsuranceCancelledReason.Enabled = false;
        }
        #endregion

    }

    private void ProposalNotification()
    {
        string _strSql, _providerName, _providerEmail, _providerCCEmail, _providerBCCEmail, _Date, _Time, _InsuranceName, _RefNo;
        MyDatabase _db = new MyDatabase();
        DataTable _dtProvider = new DataTable();
        DataTable _dtInsurance = new DataTable();
        _Date = "";
        _Time = "";
        _RefNo = "";
        _strSql = "";
        _providerName = "";
        _providerEmail = "";
        _providerCCEmail = "";
        _providerBCCEmail = "";
        _InsuranceName = "Personal Accident Insurance";
        _strSql = "SELECT [CompanyName], [Email1] FROM tblProviderCompany WHERE ProviderCompanyId = 35";
        _dtProvider = _db.GetDataTable(_strSql);
        if (_dtProvider.Rows.Count > 0)
        {
            _providerName = _dtProvider.Rows[0]["CompanyName"].ToString();
            //_providerEmail = _dtProvider.Rows[0]["Email1"].ToString();
            //_providerEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ProposalNotificationReceiver");
        }

        _providerEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("EQPA_TO");
        _providerCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("EQPA_CC");
        _providerBCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("EQPA_BCC");

        _strSql = "";
        _strSql = "SELECT CONVERT(VARCHAR,ModifiedDate,103) AS [Date], CONVERT(VARCHAR,ModifiedDate,108) AS [Time] ";
        _strSql += " FROM  tblPAProposal_EQ WHERE PAId = " + Session[General.PAId].ToString() + " ORDER BY ModifiedDate DESC";
        _dtInsurance = _db.GetDataTable(_strSql);
        if (_dtInsurance.Rows.Count > 0)
        {
            _Date = _dtInsurance.Rows[0]["Date"].ToString();
            _Time = _dtInsurance.Rows[0]["Time"].ToString();
        }
        //_RefNo = General.GetRefNumber("PA", _Date, Session[General.PAId].ToString());
        string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.PAId].ToString()));
        _RefNo = "PAQ" + convertno.ToString();

        if ((_dtProvider.Rows.Count > 0) && (_dtInsurance.Rows.Count > 0))
        {
            MyMailManager.SendProposalCompleteNotification(_providerName, _providerEmail, _providerCCEmail, _providerBCCEmail, _InsuranceName, _Date, _Time, _RefNo);
        }

    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        #region Proposal Details
        //Salutation
        //ddlSalutation.ChangeValidationEffectServerSide(strValidationGroup);
        //Name
        if (rfvName.Enabled && rfvName.ValidationGroup == strValidationGroup)
        {
            rfvName.Validate();
            if (rfvName.IsValid == false)
            {
                txtName.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtName.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "";
        }

        if (revName.Enabled && revName.ValidationGroup == strValidationGroup)
        {
            if (rfvName.IsValid)
            {
                revName.Validate();
                if (revName.IsValid == false)
                {
                    txtName.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtName.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "";
        }
        //Postal Code
        if (rfvPostCode.Enabled && rfvPostCode.ValidationGroup == strValidationGroup)
        {
            rfvPostCode.Validate();
            if (rfvPostCode.IsValid == false)
            {
                txtPostCode.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtPostCode.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "";
        }

        if (revPostCode.Enabled && revPostCode.ValidationGroup == strValidationGroup)
        {
            if (rfvPostCode.IsValid)
            {
                revPostCode.Validate();
                if (revPostCode.IsValid == false)
                {
                    txtPostCode.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtPostCode.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "";
        }

        //Unit No
        if (rfvUnit1.Enabled && rfvUnit1.ValidationGroup == strValidationGroup)
        {
            rfvUnit1.Validate();
            if (rfvUnit1.IsValid == false)
            {
                txtUnit1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtUnit1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtUnit1.ControlStyle.CssClass = "";
        }

        //Home No
        if (rfvUnit2.Enabled && rfvUnit2.ValidationGroup == strValidationGroup)
        {
            rfvUnit2.Validate();
            if (rfvUnit2.IsValid == false)
            {
                txtUnit2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtUnit2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtUnit2.ControlStyle.CssClass = "";
        }

        //Address
        if (rfvAddress.Enabled && rfvAddress.ValidationGroup == strValidationGroup)
        {
            rfvAddress.Validate();
            if (rfvAddress.IsValid == false)
            {
                txtAddress.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtAddress.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtAddress.ControlStyle.CssClass = "";
        }

        //if (revAddress.Enabled && revAddress.ValidationGroup == strValidationGroup)
        //{
        //    if (rfvAddress.IsValid)
        //    {
        //        revAddress.Validate();
        //        if (revAddress.IsValid == false)
        //        {
        //            txtAddress.ControlStyle.CssClass = "validationError";
        //        }
        //        else
        //        {
        //            txtAddress.ControlStyle.CssClass = "";
        //        }
        //    }
        //}
        //else
        //{
        //    txtAddress.ControlStyle.CssClass = "";
        //}

        //Gender
        ddlGender.ChangeValidationEffectServerSide(strValidationGroup);

        //Id Number
        ddlIdNumber.ChangeValidationEffectServerSide(strValidationGroup);
        //Nationality
        ddlNationality.ChangeValidationEffectServerSide(strValidationGroup);
        //Mobile Number
        txtMobileNo.ChangeValidationEffectServerSide(strValidationGroup);

        if (rfvEmail.Enabled && rfvEmail.ValidationGroup == strValidationGroup)
        {
            rfvEmail.Validate();
            if (rfvEmail.IsValid == false)
            {
                txtEmail.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtEmail.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtEmail.ControlStyle.CssClass = "";
        }

        if (revEmail.Enabled && revEmail.ValidationGroup == strValidationGroup)
        {
            if (rfvEmail.IsValid)
            {
                revEmail.Validate();
                if (revEmail.IsValid == false)
                {
                    txtEmail.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtEmail.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtEmail.ControlStyle.CssClass = "";
        }

        //if (rfvNatureofBusiness.Enabled && rfvNatureofBusiness.ValidationGroup == strValidationGroup)
        //{
        //    if (rfvNatureofBusiness.IsValid)
        //    {
        //        rfvNatureofBusiness.Validate();
        //        if (rfvNatureofBusiness.IsValid == false)
        //        {
        //            ddlNatureOfBusiness.ControlStyle.CssClass = "validationError";
        //        }
        //        else
        //        {
        //            ddlNatureOfBusiness.ControlStyle.CssClass = "";
        //        }
        //    }
        //}
        //else
        //{
        //    ddlNatureOfBusiness.ControlStyle.CssClass = "";
        //}

        #endregion

        #region Spouse Details
        //Spouse Name
        if (rfvSpouseName.Enabled && rfvSpouseName.ValidationGroup == strValidationGroup)
        {
            rfvSpouseName.Validate();
            if (rfvSpouseName.IsValid == false)
            {
                txtSpouseName.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtSpouseName.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtSpouseName.ControlStyle.CssClass = "";
        }

        if (revSpouseName.Enabled && revSpouseName.ValidationGroup == strValidationGroup)
        {
            if (rfvSpouseName.IsValid)
            {
                revSpouseName.Validate();
                if (revSpouseName.IsValid == false)
                {
                    txtSpouseName.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtSpouseName.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtSpouseName.ControlStyle.CssClass = "";
        }

        ddlSpouseGender.ChangeValidationEffectServerSide(strValidationGroup);
        ddlSpouseIdNumber.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlSpouseNationality.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlSpouseRelationship.ChangeValidationEffectServerSide(strValidationGroup);

        #endregion

        #region Child Details

        //Child 1
        if (rfvChildName1.Enabled && rfvChildName1.ValidationGroup == strValidationGroup)
        {
            rfvChildName1.Validate();
            if (rfvChildName1.IsValid == false)
            {
                txtChildName1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtChildName1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtChildName1.ControlStyle.CssClass = "";
        }

        if (revChildName1.Enabled && revChildName1.ValidationGroup == strValidationGroup)
        {
            if (rfvChildName1.IsValid)
            {
                revChildName1.Validate();
                if (revChildName1.IsValid == false)
                {
                    txtChildName1.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtChildName1.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtChildName1.ControlStyle.CssClass = "";
        }

        ddlChildDOB1.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildGender1.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildIdNumber1.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildNationality1.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildRelationship1.ChangeValidationEffectServerSide(strValidationGroup);

        //Child 2
        if (rfvChildName2.Enabled && rfvChildName2.ValidationGroup == strValidationGroup)
        {
            rfvChildName2.Validate();
            if (rfvChildName2.IsValid == false)
            {
                txtChildName2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtChildName2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtChildName2.ControlStyle.CssClass = "";
        }

        if (revChildName2.Enabled && revChildName2.ValidationGroup == strValidationGroup)
        {
            if (rfvChildName2.IsValid)
            {
                revChildName2.Validate();
                if (revChildName2.IsValid == false)
                {
                    txtChildName2.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtChildName2.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtChildName2.ControlStyle.CssClass = "";
        }

        ddlChildDOB2.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildGender2.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildIdNumber2.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildNationality2.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildRelationship2.ChangeValidationEffectServerSide(strValidationGroup);

        //Child 3
        if (rfvChildName3.Enabled && rfvChildName3.ValidationGroup == strValidationGroup)
        {
            rfvChildName3.Validate();
            if (rfvChildName3.IsValid == false)
            {
                txtChildName3.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtChildName3.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtChildName3.ControlStyle.CssClass = "";
        }

        if (revChildName3.Enabled && revChildName3.ValidationGroup == strValidationGroup)
        {
            if (rfvChildName3.IsValid)
            {
                revChildName3.Validate();
                if (revChildName3.IsValid == false)
                {
                    txtChildName3.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtChildName3.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtChildName3.ControlStyle.CssClass = "";
        }

        ddlChildDOB3.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildGender3.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildIdNumber3.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildNationality3.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildRelationship3.ChangeValidationEffectServerSide(strValidationGroup);

        //Child 4
        if (rfvChildName4.Enabled && rfvChildName4.ValidationGroup == strValidationGroup)
        {
            rfvChildName4.Validate();
            if (rfvChildName4.IsValid == false)
            {
                txtChildName4.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtChildName4.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtChildName4.ControlStyle.CssClass = "";
        }

        if (revChildName4.Enabled && revChildName4.ValidationGroup == strValidationGroup)
        {
            if (rfvChildName4.IsValid)
            {
                revChildName4.Validate();
                if (revChildName4.IsValid == false)
                {
                    txtChildName4.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtChildName4.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtChildName4.ControlStyle.CssClass = "";
        }

        ddlChildDOB4.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildGender4.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildIdNumber4.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildNationality4.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildRelationship4.ChangeValidationEffectServerSide(strValidationGroup);

        //Child 5
        if (rfvChildName5.Enabled && rfvChildName5.ValidationGroup == strValidationGroup)
        {
            rfvChildName5.Validate();
            if (rfvChildName5.IsValid == false)
            {
                txtChildName5.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtChildName5.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtChildName5.ControlStyle.CssClass = "";
        }

        if (revChildName5.Enabled && revChildName5.ValidationGroup == strValidationGroup)
        {
            if (rfvChildName5.IsValid)
            {
                revChildName5.Validate();
                if (revChildName5.IsValid == false)
                {
                    txtChildName5.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtChildName5.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtChildName5.ControlStyle.CssClass = "";
        }

        ddlChildDOB5.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildGender5.ChangeValidationEffectServerSide(strValidationGroup);
        ddlChildIdNumber5.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildNationality5.ChangeValidationEffectServerSide(strValidationGroup);
        //ddlChildRelationship5.ChangeValidationEffectServerSide(strValidationGroup);

        #endregion

        #region Other Info

        if (rfvOccDuties.Enabled && rfvOccDuties.ValidationGroup == strValidationGroup)
        {
            rfvOccDuties.Validate();
            if (rfvOccDuties.IsValid == false)
            {
                lblAdministrative.ControlStyle.CssClass = "validationError";
                lblSupervisory.ControlStyle.CssClass = "validationError";
                lblManual.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblAdministrative.ControlStyle.CssClass = "";
                lblSupervisory.ControlStyle.CssClass = "";
                lblManual.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblAdministrative.ControlStyle.CssClass = "";
            lblSupervisory.ControlStyle.CssClass = "";
            lblManual.ControlStyle.CssClass = "";
        }

        //PerformManual
        if (rfvPerformManual.Enabled && rfvPerformManual.ValidationGroup == strValidationGroup)
        {
            rfvPerformManual.Validate();
            if (rfvPerformManual.IsValid == false)
            {
                lblYesPerformManual.ControlStyle.CssClass = "validationError";
                lblNoPerformManual.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesPerformManual.ControlStyle.CssClass = "";
                lblNoPerformManual.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesPerformManual.ControlStyle.CssClass = "";
            lblNoPerformManual.ControlStyle.CssClass = "";
        }
        //PerformManual Reson
        if (rfvPerformManualReason.Enabled && rfvPerformManualReason.ValidationGroup == strValidationGroup)
        {
            rfvPerformManualReason.Validate();
            if (rfvPerformManualReason.IsValid == false)
            {
                txtPerformManualReason.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtPerformManualReason.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtPerformManualReason.ControlStyle.CssClass = "";
        }

        //HazadousHobby 
        if (rfvHazadousHobby.Enabled && rfvHazadousHobby.ValidationGroup == strValidationGroup)
        {
            rfvHazadousHobby.Validate();
            if (rfvHazadousHobby.IsValid == false)
            {
                lblYesHazadousHobby.ControlStyle.CssClass = "validationError";
                lblNoHazadousHobby.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesHazadousHobby.ControlStyle.CssClass = "";
                lblNoHazadousHobby.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesHazadousHobby.ControlStyle.CssClass = "";
            lblNoHazadousHobby.ControlStyle.CssClass = "";
        }
        //Hazadous Hobby Reason
        if (rfvHazadousHobbyReason.Enabled && rfvHazadousHobbyReason.ValidationGroup == strValidationGroup)
        {
            rfvHazadousHobbyReason.Validate();
            if (rfvHazadousHobbyReason.IsValid == false)
            {
                txtHazadousHobbyReason.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtHazadousHobbyReason.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtHazadousHobbyReason.ControlStyle.CssClass = "";
        }

        //Physicaldefect
        if (rfvPhysicaldefect.Enabled && rfvPhysicaldefect.ValidationGroup == strValidationGroup)
        {
            rfvPhysicaldefect.Validate();
            if (rfvPhysicaldefect.IsValid == false)
            {
                lblYesPhysicaldefect.ControlStyle.CssClass = "validationError";
                lblNoPhysicaldefect.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesPhysicaldefect.ControlStyle.CssClass = "";
                lblNoPhysicaldefect.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesPhysicaldefect.ControlStyle.CssClass = "";
            lblNoPhysicaldefect.ControlStyle.CssClass = "";
        }
        //Physicaldefect Reason
        if (rfvPhysicaldefectReason.Enabled && rfvPhysicaldefectReason.ValidationGroup == strValidationGroup)
        {
            rfvPhysicaldefectReason.Validate();
            if (rfvPhysicaldefectReason.IsValid == false)
            {
                txtPhysicaldefectReason.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtPhysicaldefectReason.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtPhysicaldefectReason.ControlStyle.CssClass = "";
        }

        //OtherInsurence
        if (rfvOI.Enabled && rfvOI.ValidationGroup == strValidationGroup)
        {
            rfvOI.Validate();
            if (rfvOI.IsValid == false)
            {
                lblYesOtherInsurence.ControlStyle.CssClass = "validationError";
                lblNoOtherInsurence.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesOtherInsurence.ControlStyle.CssClass = "";
                lblNoOtherInsurence.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesOtherInsurence.ControlStyle.CssClass = "";
            lblNoOtherInsurence.ControlStyle.CssClass = "";
        }
        //OtherInsurence Company
        if (rfvInsuranceCompany.Enabled && rfvInsuranceCompany.ValidationGroup == strValidationGroup)
        {
            rfvInsuranceCompany.Validate();
            if (rfvInsuranceCompany.IsValid == false)
            {
                ddlInsuranceCompany.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlInsuranceCompany.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlInsuranceCompany.ControlStyle.CssClass = "";
        }

        //Declined Reason
        if (rfvDeclinedIns.Enabled && rfvDeclinedIns.ValidationGroup == strValidationGroup)
        {
            rfvDeclinedIns.Validate();
            if (rfvDeclinedIns.IsValid == false)
            {
                lblYesDeclined.ControlStyle.CssClass = "validationError";
                lblNoDeclined.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesDeclined.ControlStyle.CssClass = "";
                lblNoDeclined.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesDeclined.ControlStyle.CssClass = "";
            lblNoDeclined.ControlStyle.CssClass = "";
        }
        //AnyClaims Resion
        if (rfvDeclinedInsReason.Enabled && rfvDeclinedInsReason.ValidationGroup == strValidationGroup)
        {
            rfvDeclinedInsReason.Validate();
            if (rfvDeclinedInsReason.IsValid == false)
            {
                txtDeclinedInsReason.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDeclinedInsReason.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDeclinedInsReason.ControlStyle.CssClass = "";
        }

        //Insurance Cancelled
        if (rfvInsuranceCancelled.Enabled && rfvInsuranceCancelled.ValidationGroup == strValidationGroup)
        {
            rfvInsuranceCancelled.Validate();
            if (rfvInsuranceCancelled.IsValid == false)
            {
                lblYesInsuranceCancelled.ControlStyle.CssClass = "validationError";
                lblNoInsuranceCancelled.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesInsuranceCancelled.ControlStyle.CssClass = "";
                lblNoInsuranceCancelled.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesInsuranceCancelled.ControlStyle.CssClass = "";
            lblNoInsuranceCancelled.ControlStyle.CssClass = "";
        }
        //InsuranceCancelled Reson
        if (rfvInsuranceCancelledReason.Enabled && rfvInsuranceCancelledReason.ValidationGroup == strValidationGroup)
        {
            rfvInsuranceCancelledReason.Validate();
            if (rfvInsuranceCancelledReason.IsValid == false)
            {
                txtInsuranceCancelledReason.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtInsuranceCancelledReason.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtInsuranceCancelledReason.ControlStyle.CssClass = "";
        }

        #endregion

        #region Payment Mode

        //Name of the Card
        if (rfvNameoftheCard.Enabled && rfvNameoftheCard.ValidationGroup == strValidationGroup)
        {
            rfvNameoftheCard.Validate();
            if (rfvNameoftheCard.IsValid == false)
            {
                txtNameoftheCard.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNameoftheCard.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNameoftheCard.ControlStyle.CssClass = "";
        }
        //Issuing Bank
        if (rfvIssuingBank.Enabled && rfvIssuingBank.ValidationGroup == strValidationGroup)
        {
            rfvIssuingBank.Validate();
            if (rfvIssuingBank.IsValid == false)
            {
                txtIssuingBank.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtIssuingBank.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtIssuingBank.ControlStyle.CssClass = "";
        }
        //Card 1
        if (rfvCardNo1.Enabled && rfvCardNo1.ValidationGroup == strValidationGroup)
        {
            rfvCardNo1.Validate();
            if (rfvCardNo1.IsValid == false)
            {
                txtCardNo1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo1.ControlStyle.CssClass = "";
        }

        if (revCardNo1.Enabled && revCardNo1.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo1.IsValid)
            {
                revCardNo1.Validate();
                if (revCardNo1.IsValid == false)
                {
                    txtCardNo1.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo1.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo1.ControlStyle.CssClass = "";
        }
        //Card 2
        if (rfvCardNo2.Enabled && rfvCardNo2.ValidationGroup == strValidationGroup)
        {
            rfvCardNo2.Validate();
            if (rfvCardNo2.IsValid == false)
            {
                txtCardNo2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo2.ControlStyle.CssClass = "";
        }

        if (revCardNo2.Enabled && revCardNo2.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo2.IsValid)
            {
                revCardNo2.Validate();
                if (revCardNo2.IsValid == false)
                {
                    txtCardNo2.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo2.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo2.ControlStyle.CssClass = "";
        }
        //Card 3
        if (rfvCardNo3.Enabled && rfvCardNo3.ValidationGroup == strValidationGroup)
        {
            rfvCardNo3.Validate();
            if (rfvCardNo3.IsValid == false)
            {
                txtCardNo3.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo3.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo3.ControlStyle.CssClass = "";
        }

        if (revCardNo3.Enabled && revCardNo3.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo3.IsValid)
            {
                revCardNo3.Validate();
                if (revCardNo3.IsValid == false)
                {
                    txtCardNo3.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo3.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo3.ControlStyle.CssClass = "";
        }
        //Card 4
        if (rfvCardNo4.Enabled && rfvCardNo4.ValidationGroup == strValidationGroup)
        {
            rfvCardNo4.Validate();
            if (rfvCardNo4.IsValid == false)
            {
                txtCardNo4.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo4.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo4.ControlStyle.CssClass = "";
        }

        if (revCardNo4.Enabled && revCardNo4.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo4.IsValid)
            {
                revCardNo4.Validate();
                if (revCardNo4.IsValid == false)
                {
                    txtCardNo4.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo4.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo4.ControlStyle.CssClass = "";
        }
        //Card Expiry Month
        if (rfvCardExpiryMonth.Enabled && rfvCardExpiryMonth.ValidationGroup == strValidationGroup)
        {
            rfvCardExpiryMonth.Validate();
            if (rfvCardExpiryMonth.IsValid == false)
            {
                ddlCardExpiryMonth.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlCardExpiryMonth.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlCardExpiryMonth.ControlStyle.CssClass = "";
        }

        //Card Expiry Year
        if (rfvCardExpiryYear.Enabled && rfvCardExpiryYear.ValidationGroup == strValidationGroup)
        {
            rfvCardExpiryYear.Validate();
            if (rfvCardExpiryYear.IsValid == false)
            {
                ddlCardExpiryYear.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlCardExpiryYear.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlCardExpiryYear.ControlStyle.CssClass = "";
        }


        //CardType
        if (rfvCardType.Enabled && rfvCardType.ValidationGroup == strValidationGroup)
        {
            rfvCardType.Validate();
            if (rfvCardType.IsValid == false)
            {
                lblVisa.ControlStyle.CssClass = "validationError";
                lblMasterCard.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblVisa.ControlStyle.CssClass = "";
                lblMasterCard.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblVisa.ControlStyle.CssClass = "";
            lblMasterCard.ControlStyle.CssClass = "";
        }

        #endregion

    }

    protected void csvCreditCardValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
        bool _status = true;
        string _first = txtCardNo1.Text.Trim().Substring(0, 1);
        if (rdoVisa.Checked)
        {
            if (_first != "4")
            {
                _status = false;
            }
        }
        else if (rdoMasterCard.Checked)
        {
            if (_first != "5")
            {
                _status = false;
            }
        }
        if (_status == true)
        {
            txtCreditCardValid.Text = "";
            txtCreditCardValid.Text = txtCardNo1.Text.Trim() + "" + txtCardNo2.Text.Trim() + "" + txtCardNo3.Text.Trim() + "" + txtCardNo4.Text.Trim();
            string _cardNumer = txtCreditCardValid.Text;
            MySecurity _mysecurity = new MySecurity();
            if (_mysecurity.IsCreditCardValid(_cardNumer))
            {
                args.IsValid = true;
            }
            else
            {
                args.IsValid = false;
            }
        }
        else
        {
            args.IsValid = false;
        }
    }

    protected void csvCCExpiredValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
        txtCCExpiredValid.Text = "";
        txtCCExpiredValid.Text = "valid";
        Int32 _Year = Convert.ToInt32(ddlCardExpiryYear.Text);
        Int32 _Month = Convert.ToInt32(ddlCardExpiryMonth.Text);

        MySecurity _mysecurity = new MySecurity();
        if (_mysecurity.IsCreditCardExpiredDateValid(_Year, _Month))
        {
            args.IsValid = true;
        }
        else
        {
            args.IsValid = false;
        }
    }

    protected void CheckSalGenderValid(object sender, ServerValidateEventArgs args)
    {
        //string _sal = ddlSalutation.GetSalutation();
        //string _gender = ddlGender.GetGender();
        //if (_gender == "M")
        //{
        //    if (_sal == "Ms" || _sal == "Miss" || _sal == "Mdm" || _sal == "Mrs")
        //    {
        //        args.IsValid = false;
        //    }
        //}
        //else if (_gender == "F")
        //{
        //    if (_sal == "Mr")
        //    {
        //        args.IsValid = false;
        //    }
        //}
        //else
        //{
        //    args.IsValid = true;
        //}
    }

    protected void Check2NRICValid(object sender, ServerValidateEventArgs args)
    {
        string _appID = ddlIdNumber.GetIdNumber();
        string _spouseID = ddlSpouseIdNumber.GetIdNumber();

        if (_appID == _spouseID)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }

    }

    private void EnableChildPanels()
    {
        if (txtIsCover.Text.Trim() == "INDSP" || txtIsCover.Text.Trim() == "INDSPCHD")
        {
            pnlSpouse.Visible = true;
            rfvSpouseName.Enabled = true;
            revSpouseName.Enabled = true;
            //csvNRIC.Enabled = true;
            //ddlSpouseGender.IsEnableValidation(true);
            ddlSpouseIdNumber.IsEnableValidation(true);
            //ddlSpouseNationality.IsEnableValidation(true);
            //ddlSpouseRelationship.IsEnableValidation(true);            
        }
        else
        {
            pnlSpouse.Visible = false;
            rfvSpouseName.Enabled = false;
            revSpouseName.Enabled = false;
            //csvNRIC.Enabled = false;
            //ddlSpouseGender.IsEnableValidation(false);
            ddlSpouseIdNumber.IsEnableValidation(false);
            //ddlSpouseNationality.IsEnableValidation(false);
            //ddlSpouseRelationship.IsEnableValidation(false);
        }
        if (txtCHCount.Text.Trim() == "0")
        {
            pnlChildParticulars.Visible = false;
            pnlChild1.Visible = false;
            pnlChild2.Visible = false;
            pnlChild3.Visible = false;
            pnlChild4.Visible = false;
            pnlChild5.Visible = false;

            ValidateChild1(false);
            ValidateChild2(false);
            ValidateChild3(false);
            ValidateChild4(false);
            ValidateChild5(false);
        }
        else if (txtCHCount.Text.Trim() == "1")
        {
            pnlChildParticulars.Visible = true;
            pnlChild1.Visible = true;
            pnlChild2.Visible = false;
            pnlChild3.Visible = false;
            pnlChild4.Visible = false;
            pnlChild5.Visible = false;

            ValidateChild1(true);
            ValidateChild2(false);
            ValidateChild3(false);
            ValidateChild4(false);
            ValidateChild5(false);
        }
        else if (txtCHCount.Text.Trim() == "2")
        {
            pnlChildParticulars.Visible = true;
            pnlChild1.Visible = true;
            pnlChild2.Visible = true;
            pnlChild3.Visible = false;
            pnlChild4.Visible = false;
            pnlChild5.Visible = false;

            ValidateChild1(true);
            ValidateChild2(true);
            ValidateChild3(false);
            ValidateChild4(false);
            ValidateChild5(false);
        }
        else if (txtCHCount.Text.Trim() == "3")
        {
            pnlChildParticulars.Visible = true;
            pnlChild1.Visible = true;
            pnlChild2.Visible = true;
            pnlChild3.Visible = true;
            pnlChild4.Visible = false;
            pnlChild5.Visible = false;

            ValidateChild1(true);
            ValidateChild2(true);
            ValidateChild3(true);
            ValidateChild4(false);
            ValidateChild5(false);
        }
        else if (txtCHCount.Text.Trim() == "4")
        {
            pnlChildParticulars.Visible = true;
            pnlChild1.Visible = true;
            pnlChild2.Visible = true;
            pnlChild3.Visible = true;
            pnlChild4.Visible = true;
            pnlChild5.Visible = false;

            ValidateChild1(true);
            ValidateChild2(true);
            ValidateChild3(true);
            ValidateChild4(true);
            ValidateChild5(false);
        }
        else if (txtCHCount.Text.Trim() == "5")
        {
            pnlChildParticulars.Visible = true;
            pnlChild1.Visible = true;
            pnlChild2.Visible = true;
            pnlChild3.Visible = true;
            pnlChild4.Visible = true;
            pnlChild5.Visible = true;

            ValidateChild1(true);
            ValidateChild2(true);
            ValidateChild3(true);
            ValidateChild4(true);
            ValidateChild5(true);
        }
    }

    private void ValidateChild1(bool OnOff)
    {
        rfvChildName1.Enabled = OnOff;
        revChildName1.Enabled = OnOff;
        ddlChildDOB1.IsEnableValidation(OnOff);
        ddlChildGender1.IsEnableValidation(OnOff);
        ddlChildIdNumber1.IsEnableValidation(OnOff);
        //ddlChildNationality1.IsEnableValidation(OnOff);
        //ddlChildRelationship1.IsEnableValidation(OnOff);
    }

    private void ValidateChild2(bool OnOff)
    {
        rfvChildName2.Enabled = OnOff;
        revChildName2.Enabled = OnOff;
        ddlChildDOB2.IsEnableValidation(OnOff);
        ddlChildGender2.IsEnableValidation(OnOff);
        ddlChildIdNumber2.IsEnableValidation(OnOff);
        //ddlChildNationality2.IsEnableValidation(OnOff);
        //ddlChildRelationship2.IsEnableValidation(OnOff);
    }

    private void ValidateChild3(bool OnOff)
    {
        rfvChildName3.Enabled = OnOff;
        revChildName3.Enabled = OnOff;
        ddlChildDOB3.IsEnableValidation(OnOff);
        ddlChildGender3.IsEnableValidation(OnOff);
        ddlChildIdNumber3.IsEnableValidation(OnOff);
        //ddlChildNationality3.IsEnableValidation(OnOff);
        //ddlChildRelationship3.IsEnableValidation(OnOff);
    }

    private void ValidateChild4(bool OnOff)
    {
        rfvChildName4.Enabled = OnOff;
        revChildName4.Enabled = OnOff;
        ddlChildDOB4.IsEnableValidation(OnOff);
        ddlChildGender4.IsEnableValidation(OnOff);
        ddlChildIdNumber4.IsEnableValidation(OnOff);
        //ddlChildNationality4.IsEnableValidation(OnOff);
        //ddlChildRelationship4.IsEnableValidation(OnOff);
    }

    private void ValidateChild5(bool OnOff)
    {
        rfvChildName5.Enabled = OnOff;
        revChildName5.Enabled = OnOff;
        ddlChildDOB5.IsEnableValidation(OnOff);
        ddlChildGender5.IsEnableValidation(OnOff);
        ddlChildIdNumber5.IsEnableValidation(OnOff);
        //ddlChildNationality5.IsEnableValidation(OnOff);
        //ddlChildRelationship5.IsEnableValidation(OnOff);
    }

    private void ShowUserDetails()
    {
        //hplEditProfile.Visible = true;
        CE.User.Profile _profile = new CE.User.Profile();
        CE.User.ProfileDB _profiledb = new ProfileDB();
        CE.User.Contact _contact = new Contact();
        CE.User.ContactDB _contactdb = new ContactDB();

        Int64 UserId = Convert.ToInt64(Session[General.UserId].ToString());
        _profile = _profiledb.GetProfile(UserId);
        if (_profile != null)
        {
            txtName.Text = _profile.FirstName + " " + _profile.SurName;

            if (_profile.IDNo.Length == 9)
            {
                ddlIdNumber.Prefix = _profile.IDNo[0].ToString();
                ddlIdNumber.Postfix = _profile.IDNo[8].ToString();
                ddlIdNumber.IDNumber = _profile.IDNo.Substring(1, 7);
            }

            if (_profile.Gender.ToString() != "")
            {
                ddlGender.Gender = _profile.Gender.ToString();
            }

            if (_profile.Nationality != "")
            {
                ddlNationality.Nationality = _profile.Nationality.ToString();
            }

            _contact = _contactdb.GetContact(UserId);
            if (_contact != null)
            {
                txtMobileNo.PhoneNo = _contact.Mobile;
                txtOfficePhoneNo.PhoneNo = _contact.OfficePhone;
                txtEmail.Text = _contact.Email.ToString();

            }

            _profile = null;
            _profiledb = null;
            _contact = null;
            _contactdb = null;
        }


    }

    private void GetPostCode()
    {
        rfvPostCode.Validate();
        revPostCode.Validate();
        if (rfvPostCode.IsValid && revPostCode.IsValid)
        {
            txtPostCode.ControlStyle.CssClass = "";
            txtAddress.ControlStyle.CssClass = "";
            MyLocation _myLoc = new MyLocation();
            //string _strAddress = _myLoc.GetAddressByPostCode(txtPostCode.Text);
            //if (_strAddress != null && _strAddress != string.Empty)
            //{
            //    if (_strAddress.ToLower().Contains("invalid api"))
            //    {
            //        txtAddress.Text = "Address can't be retrieved. Please type your address detail here.";
            //    }
            //    else
            //    {
            //        txtAddress.Text = _strAddress;
            //    }
            //}
            //else
            //{
            //    txtAddress.Text = "Address is not found.";
            //}

            System.Data.DataSet _ds = _myLoc.GetAddressByPostCodeDataSet(txtPostCode.Text);
            ddlAddressList.Items.Clear();
            string _lstValue;
            string _lstText;
            int _rowCount = 0;

            if (_ds != null)
            {
                if (_ds.Tables.Count > 0)
                {
                    foreach (System.Data.DataTable _dt in _ds.Tables)
                    {
                        if (_dt.Rows.Count > 0)
                        {
                            foreach (System.Data.DataRow _dr in _dt.Rows)
                            {
                                //lblAddress2.Text += _dr["t"].ToString() + "<br />";
                                //lblAddress2.Text += _dr["a"].ToString() + "<br /><br />";

                                _lstValue = _dr["t"].ToString() + ", " + _dr["a"].ToString();
                                _lstText = _dr["t"].ToString();
                                ddlAddressList.Items.Add(new ListItem(_lstText, _lstValue));
                                if (_rowCount == 0)
                                {
                                    txtAddress.Text = _lstValue;
                                    //ibtPostCode.Enabled = false;
                                    txtAddress.ReadOnly = true;
                                }

                                _rowCount++;
                            }
                        }
                        else
                        {
                            txtAddress.Text = "No address found.";
                            txtAddress.ReadOnly = false;
                            txtAddress.ControlStyle.CssClass = "validationError";
                        }
                    }
                }
                else
                {
                    txtAddress.Text = "No address found.";
                    txtAddress.ReadOnly = false;
                    txtAddress.ControlStyle.CssClass = "validationError";
                }
            }
            else
            {
                txtAddress.Text = "Please type your address here.";
                txtAddress.ReadOnly = false;
                txtAddress.ControlStyle.CssClass = "validationError";
            }

            if (_rowCount > 1)
            {
                divAddressList.Visible = true;
            }
            else
            {
                divAddressList.Visible = false;

            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "validationError";
            ddlAddressList.Items.Clear();
            divAddressList.Visible = false;
            txtAddress.Text = "Invalid postcode.";
            txtAddress.ControlStyle.CssClass = "validationError";
        }
    }

}
